<template>
  <div>
    <van-nav-bar
      title="我的购物车"
      right-text="添加新地址"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <div style="height:15rem;overflow:auto;">
      <van-card
        v-for="item in list"
        :desc="item.goods.goodsDetail"
        :title="item.goods.goodsName"
        :thumb="item.goods.imageUrl"
        :price="item.goods.goodsPrice"
        :num="item.num"
      >
        <div slot="footer">
          <van-button size="mini" @click="add(item.shoppingGoodsId)">添加</van-button>
          <van-button size="mini" @click="sub(item.shoppingGoodsId)">减少</van-button>
          <van-button size="mini" @click="del(item.shoppingGoodsId)">删除</van-button>
        </div>
      </van-card>
    </div>
    <van-submit-bar :price="1000" button-text="结算" @submit="onSubmit">
      <van-checkbox v-model="checked">全选</van-checkbox>
    </van-submit-bar>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "setsss",
  data() {
    return {
      list: [],
      list2: [],
      checked: false,
      nnn: ""
    };
  },
  methods: {
    onClickLeft() {
      this.$router.push({ path: "/cart" });
    },
    onClickRight() {
      this.$router.push({ path: "/adres" });
    },
    onSubmit() {
      this.$router.push({ path: "/payment" });
    },
    del() {},
    add(id) {
      var a = JSON.parse(localStorage.getItem("token"));
      console.log(a[0]);
      axios({
        url: "http://10.8.157.32:8080/secluxury/shoppingcar/clickadd",
        params: {
          email: a[0],
          shoppingGoodsId: id
        }
      }).then(data => {
        console.log(data);

      });
    },

    sub(id) {
      var a = JSON.parse(localStorage.getItem("token"));
      console.log(a[0]);
      axios({
        url: "http://10.8.157.32:8080/secluxury/shoppingcar/clicksubtract",
        params: {
          email: a[0],
          shoppingGoodsId: id
        }
      }).then(data => {
        console.log(data);
      });
    }
  },
  mounted() {
    var a = JSON.parse(localStorage.getItem("token"));
    // console.log(a[0]);
    axios({
      url: "http://10.8.157.32:8080/secluxury/shoppingcar/getshoppingcar",
      params: {
        email: a[0]
      }
    }).then(d => {
      // console.log(d.data);
      d.data.map(p => {
        // console.log(p.num, p.shoppingGoodsId, p.goods, p);
        this.list.push(p);
        console.log(this.list);
      });
    });
  },
  updated() {}
};
</script>

<style>
</style>